import CONSTANT from '@/common/constants.js';
import http from '@/common/http.js'
import XInput from 'vux/src/components/x-input/index.vue'
import Group from 'vux/src/components/group/index.vue'
import Datetime from 'vux/src/components/datetime/index.vue'
import Picker from 'vux/src/components/picker/index.vue'
import Popup from 'vux/src/components/popup/index.vue'
import XTextarea from 'vux/src/components/x-textarea/index.vue'

export default {
  name: 'qj',
  components: {XInput, Group, Datetime, Picker, Popup,XTextarea},
  data () {
    return {
      minYear: 1900,
      maxYear: 2017,
      show: false,
      siteId: '',
      classId: '',
      className: '',
      seq: '',
      seqTime: '',
      agentId: '',
      agentTeacherList: [],
      gradeListValue: [],
      reason: '',
      studentId: '',
      idCardNeeds: true,
      name: '',
      mobile: '',
      numID: '',
      classNum: '',
      birthday: '',
      sex: '男',
      sfzyanzhen: function (value) {
        let r = /^(\d{18}|\d{17}x)$/;
        if (r.test(value)) {
          return {
            valid: true,
            msg: '身份证正确'
          }
        } else {
          return {
            valid: false,
            msg: '身份证错误'
          }
        }
      }
    }
  },
  updated() {
    this.$nextTick(() => {
      let clientWidth = `${document.documentElement.clientWidth}`
      document.getElementById("seq_").style.width = '67%'
      document.getElementById("class_").style.width = '67%'
    })
  },
  mounted () {
    var _this = this
    _this.maxYear = new Date().getFullYear()
    _this.siteId = window.sessionStorage.getItem('siteId')
    _this.studentId = window.sessionStorage.getItem('studentId')
    _this.classId = this.$route.query.classId
    _this.className = this.$route.query.className
    _this.seq = this.$route.query.seq
    _this.seqTime = this.$route.query.seqTime
    _this.agentTeacherList = [{name: '请选择代理教师', value: ''}]
    if (_this.classId) {
      http.post(CONSTANT.agentTeachList, {
        classId: _this.classId,
        orgId: _this.siteId
      }, (res) => {
        let teacherList = res.teacherList
        for (var i = 0; i < teacherList.length; i++) {
          var listOne = {}
          listOne.name = teacherList[i].optUser.name
          listOne.value = teacherList[i].id
          _this.agentTeacherList.push(listOne)
        }
      })
    }
  },
  methods: {
    submitQJform () {
      var _this = this
      if (!_this.classId) {
        alert('请选择上课班级！')
      } else if (!_this.seq) {
        alert('请选择课次！')
      } else if (_this.reason == '') {
        alert('请填写请假理由！')
      } else {
        http.post(CONSTANT.LEAVESAVE, {
          userId: _this.studentId,
          orgId: _this.siteId,
          classId: _this.classId,
          seqs: _this.seq,
          agentId: _this.agentId,
          description: _this.reason
        }, (res) => {
          alert(res)
          this.$router.push({path: '/qj_list'})
        })
      }
    },
    chooseOK () {
      var _this = this
      _this.show = false
    },
    checkone (e) {
      // 男选择按钮
      var _this = this
      if (e.srcElement.className == 'iconfont icon-danxuan-xuanzhong iconfontChecked') {
        e.target.parentElement.children[1].className = 'iconfont icon-danxuan1 iconfontNotChecked'
        _this.sex = '男'
      } else {
        e.srcElement.className = 'iconfont icon-danxuan-xuanzhong iconfontChecked'
        e.target.parentElement.children[1].className = 'iconfont icon-danxuan1 iconfontNotChecked'
        _this.sex = '男'
      }
      console.log(this.sex)
    },
    checktwo (e) {
      // 女选择按钮
      var _this = this
      if (e.srcElement.className == 'iconfont icon-danxuan-xuanzhong iconfontChecked') {
        e.target.parentElement.children[0].className = 'iconfont icon-danxuan1 iconfontNotChecked'
        _this.sex = '女'
      } else {
        e.srcElement.className = 'iconfont icon-danxuan-xuanzhong iconfontChecked'
        e.target.parentElement.children[0].className = 'iconfont icon-danxuan1 iconfontNotChecked'
        _this.sex = '女'
      }
      console.log(this.sex)
    },
    comeBack () {
      this.$router.push({path: '/qj_list'})
    },
    goMyClassTeacher() {
      this.$router.push({path: '/myClassT'})
    },
    goMyClassSeqTeacher() {
      if (this.classId == null || this.classId == '') {
        alert('请先选择上课班级')
        return
      }
      this.$router.push({path: '/schedule_t_seq',query:{classId: this.classId,className: this.className}})
    },
    getAgentTeacherList() {
    },
    setAgerntTeacher (value) {
      this.agentId = value[0]
    }
  }
}
